package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.system.api.domain.ShCourseTeacher;
import com.ruoyi.system.utils.TencentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShCourseTeacherMapper;
import com.ruoyi.system.service.IShCourseTeacherService;

/**
 * 课程教师信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-18
 */
@Service
public class ShCourseTeacherServiceImpl implements IShCourseTeacherService 
{
    @Autowired
    private ShCourseTeacherMapper shCourseTeacherMapper;

    /**
     * 查询课程教师信息
     * 
     * @param id 课程教师信息主键
     * @return 课程教师信息
     */
    @Override
    public ShCourseTeacher selectShCourseTeacherById(Long id)
    {
        return shCourseTeacherMapper.selectShCourseTeacherById(id);
    }

    /**
     * 查询课程教师信息列表
     * 
     * @param shCourseTeacher 课程教师信息
     * @return 课程教师信息
     */
    @Override
    public List<ShCourseTeacher> selectShCourseTeacherList(ShCourseTeacher shCourseTeacher)
    {
        return shCourseTeacherMapper.selectShCourseTeacherList(shCourseTeacher);
    }

    /**
     * 新增课程教师信息
     * 
     * @param shCourseTeacher 课程教师信息
     * @return 结果
     */
    @Override
    public int insertShCourseTeacher(ShCourseTeacher shCourseTeacher)
    {
        shCourseTeacher.setCreateTime(DateUtils.getNowDate());
        return shCourseTeacherMapper.insertShCourseTeacher(shCourseTeacher);
    }

    /**
     * 修改课程教师信息
     * 
     * @param shCourseTeacher 课程教师信息
     * @return 结果
     */
    @Override
    public int updateShCourseTeacher(ShCourseTeacher shCourseTeacher)
    {
        return shCourseTeacherMapper.updateShCourseTeacher(shCourseTeacher);
    }

    /**
     * 批量删除课程教师信息
     * 
     * @param ids 需要删除的课程教师信息主键
     * @return 结果
     */
    @Override
    public int deleteShCourseTeacherByIds(Long[] ids)
    {
        TencentUtils tencentUtils = TencentUtils.getInstance();
        for (Long id:ids) {
            ShCourseTeacher item = shCourseTeacherMapper.selectShCourseTeacherById(id);
            if (null!=item.getTeacherHeadimgurl()&&!"".equals(item.getTeacherHeadimgurl())) {
                String[] keyAry = item.getTeacherHeadimgurl().split("aliyuncs.com/");
                tencentUtils.del(keyAry[1]);
            }
            shCourseTeacherMapper.deleteShCourseTeacherById(id);
        }
        return ids.length;
    }

    /**
     * 删除课程教师信息信息
     * 
     * @param id 课程教师信息主键
     * @return 结果
     */
    @Override
    public int deleteShCourseTeacherById(Long id)
    {
        return shCourseTeacherMapper.deleteShCourseTeacherById(id);
    }
}
